<template>
  <div>

  </div>
</template>

<script>
export default {
  name: 'array',
  data () {
    return {
      children: [
        { name: 'Bob', age: 18 },
        { name: 'Peter', age: 16 },
        { name: 'Lynn', age: 28 },
        { name: 'Jack', age: 38 }
      ],
      people: [
        { name: 'Bob', sex: 'boy' },
        { name: 'Peter', sex: 'boy' },
        { name: 'Lynn', sex: 'girl' },
        { name: 'Jack', sex: 'boy' }
      ],
      employees: [
        { name: 'Bob', wage: 5000 },
        { name: 'Peter', wage: 10000 },
        { name: 'Lynn', wage: 15000 },
        { name: 'Jack', wage: 20000 }
      ],
      students: [
        { name: 'Bob', grade: 100 },
        { name: 'Peter', grade: 75 },
        { name: 'Lynn', grade: 80 },
        { name: 'Jack', grade: 95 }
      ]
    }
  },
  mounted () {
    //  数组中需要每一项都符合条件才返回true,反之返回false
    let isAdults = this.children.every(child => child.age >= 18);
    console.log(isAdults)// false 因为Peter年龄小于18

    this.children[1].age = 20;//  手动修改Peter年轻为20岁
    let isAdults2 = this.children.every(child => child.age >= 18);
    console.log(isAdults2);// true

    //  数组中只需要符合一个条件就返回true，反之返回false
    let hasGirl = this.people.some(val => val.sex == 'girl');
    console.log(hasGirl);

    //  给工资小于10000的员工进行加薪10000元奖金，返回新数组
    let employeesWage = this.employees.map(item => {
      let middle = 0;
      item.wage < 10000 ? middle = item.wage + 10000 : middle = item.wage
      return {
        name: item.name,
        wage: middle
      }
    });
    console.log(employeesWage)

    //  筛选班上期末考试成绩大于等于90分的学生
    let awardStudents = this.students.filter(val => val.grade >= 90);
    console.log(awardStudents);

    //  读取每位学生的成绩，没有返回值
    this.students.forEach(item => {
      console.log(`${item.name}同学的成绩为${item.grade}`);
    });

    //  获取获得奖励的同学，没有返回值
    awardStudents.forEach(item => {
      console.log(`获取奖励的同学有${item.name}`);
    });
  }
}
</script>
<style scoped>
</style>
